package collision;



public class Bird extends Shootable
{
	//the image file path
	private static String iiName = "bird.png";
	//the birds speed
	double dy;
	//the birds acceleration when it falls
	double ddy;
	//if the bird is alive
	boolean alive;
	//the vector of the arrrow that hit this bird
	Vector2D hitVect;
	
    private final int BOARD_WIDTH = 700;
    
    /**
     * Bird Constructor
     *
     * @param  x  initial position x
     * @param  y  initial position y
     */
    public Bird(int x, int y) {
        super(x, y, iiName);
        alive = true;
        ddy=.15;

    }

    /**
     * Bird Constructor
     *
     * @param  x  initial position x
     * @param  y  initial position y
     * @param  speed  initial speed x
     */
    public Bird(int x, int y, int speed) {
        super(x, y, speed, iiName);
        alive = true;
        ddy=.15;
        dy = 0;

    }

    /**
     * overwrites the Shootable move method
     */
    public void move() 
    {
    	int posX = super.getX();
    	int posY = super.getY();
    	int speedX = super.getDX();
    	

    	if(!alive)
    	{
    		//speedX = (int)(speedX + hitVect.x*5);
    		//dy = (dy + hitVect.y*5);
    		posX += speedX;
            dy = dy + ddy;
            posY += (int)dy;
            if (posX > BOARD_WIDTH || posY > 500)
                super.setVisible(false);
            super.setPosition(posX, posY);
            super.setDX(speedX);
    	}
    	else
    		super.move();
    }
    
    /**
     * Checks if the bird is still alive.
     *
     * @return   if the bird has been hit by an arrow or not
     */
    public boolean isAlive(){
    	return alive;
    }
    
    public void wasHitBy(Missile m)
    {
    	int f = 2;
    	alive = false;
    	hitVect = m.getVector();
    	dy = (dy + hitVect.y*f);
    	super.setDX((int)(super.getDX() + hitVect.x*f));
    	
    }
}
